﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel_Project.Tools.MySqlData_Helps
{
    /// <summary>
    /// 不通过异步执行一条Sql语句,传入什么Sql语句就执行一条Sql语句,并返回一条结果(int类型)
    /// </summary>
    internal class ExecuteMySql
    {
        /// <summary>
        /// 连接数据库，返回连接成功之后MySqlConnection数据库连接对象，一定要下载MySql包
        /// </summary>
        /// <param name="mySqlconnand">MySql连接语句</param>
        /// <param name="sql">MySql语句</param>
        /// <returns></returns>
        public static int MySql(string mySqlconnand,string sql)
        {
            using (var conn = new MySqlConnection(mySqlconnand))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("",conn);
                cmd.CommandText = sql;
                try
                {
                    return cmd.ExecuteNonQuery();
                }catch (Exception ex)
                {
                    return -1;
                }
            }
        }
    }
}
